package com.zpself.module.io.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2020/7/21 15:46
 * @Modified By
 */
@RestController
@RequestMapping("/uploadFile")
public class UploadFile {
    @PostMapping("/upload")
    @ResponseBody
    public Map<String, String> upload1(@RequestParam("file") MultipartFile file) throws IOException {
        System.out.println("[文件类型] - [{}]"+ file.getContentType());
        System.out.println("[文件名称] - [{}]"+ file.getOriginalFilename());
        System.out.println("[文件大小] - [{}]"+ file.getSize());
        //保存
        file.transferTo(new File("D:\\gitrep\\springboot\\testFile\\" + file.getOriginalFilename()));
        Map<String, String> result = new HashMap<>(16);
        result.put("contentType", file.getContentType());
        result.put("fileName", file.getOriginalFilename());
        result.put("fileSize", file.getSize() + "");
        return result;
    }
}
